﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using StudentWeb.DAL;
using StudentWeb.Model;
using StudentWeb.Common;
/*  public IResult GetBookInfo(int bookID)*/
namespace StudentWeb.BLL
{

    public class BookBO
    {
        #region 书籍信息 单条记录
        /// <summary>
        /// 书籍信息 单条记录
        /// </summary>
        /// <param name="bookID"></param>
        /// <returns></returns>
          #endregion
        #region 书籍信息 保存
        public bool SaveBookInfo(dynamic data)
       {
           int bookID = data.BookID ?? 0;
           var result = 0;
           if (bookID > 0)
           {
               var record = new BookDataDAO().GetInfo(bookID);
               record.BookName = data.BookName;
               record.BookNo = data.BookNo;
               result = new BookDataDAO().Update(record);
           }
           else if (bookID == 0)
           {
               var book = new BookData()
               {
                   BookName = data.BookName,
                   BookNo = data.BookNo,
               };
               result = new BookDataDAO().Insert(book);
           }
           return result > 0;
       }
        #endregion
        #region 书籍信息 删除
        public IResult DeleteBookInfo(int bookID)
        {
            int res = new BookDataDAO().Delete(bookID);
            if (res > 0)
            {
                return new Result(ResultCode.Success);
            }
            return new Result(ResultCode.Fail);
        }
        #endregion
        #region 书籍信息 添加
         public bool InsertBookInfo(dynamic data)
         {
             var result = 0;
             // var res = new BookDataDAO().GetInfo(bookID);
             // return new DataResult<BookData>(res);
             var book = new BookData()
             {
                 BookName = data.BookName,
                 BookNo = data.BookNo,
             };
             result = new BookDataDAO().Insert(book);
             return result > 0;
         }
        #endregion
        #region 书籍信息 修改
         public bool UpdateBookInfo(dynamic data)
         {
             int bookID = data.BookID;
             var result = 0;
             var record = new BookDataDAO().GetInfo(bookID);
             record.BookName = data.BookName;
             record.BookNo = data.BookNo;
             result = new BookDataDAO().Update(record);
             return result > 0;
         }
        #endregion
        #region 书籍信息 全部记录
        /// <summary>
        /// 书籍信息 全部记录
        /// </summary>
        /// <param name="bookID"></param>
        /// <returns></returns>
        public IResult GetBookList()
        {
            var list = new BookDataDAO().GetList();
            return new DataResult(list);
        }
        #endregion
        #region 学生信息 分页列表
        /// <summary>
        /// 学生信息 分页列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="wc"></param>
        /// <returns></returns>
        public IResult GetBookList(int pageIndex, int pageSize, string wc = null)
        {
            var list = new BookDataDAO().GetBookList(pageIndex, pageSize, wc);
            return new DataResult<PagedList<dynamic>>(list);
        }
        #endregion
    }
}
